package com.tsing.wms.controller;


import com.tsing.wms.service.IGoodsService;
import com.tsing.wms.util.ResultUtil;
import com.tsing.wms.valid.AddGroup;
import com.tsing.wms.valid.UpdateGroup;
import com.tsing.wms.vo.PageResultVO;
import com.tsing.wms.vo.ResultData;
import com.tsing.wms.vo.req.GoodsReqVO;
import com.tsing.wms.vo.req.IdReqVO;
import com.tsing.wms.vo.req.IdsReqVO;
import com.tsing.wms.vo.req.SupplierPageReqVO;
import com.tsing.wms.vo.resp.GoodsRespVO;
import com.tsing.wms.vo.resp.IdAndNameRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 货物表 前端控制器
 * </p>
 *
 * @author TheTsing
 * @since 2022-04-13
 */
@Api(tags = "货物管理")
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private IGoodsService goodsService;

    @GetMapping("/supplierList")
    @ApiOperation(value = "供应商列表")
    public ResultData<List<IdAndNameRespVO>> supplierList() {
        return ResultUtil.success(goodsService.supplierList());
    }

    @PostMapping("/addGoods")
    @ApiOperation(value = "新增货物")
    public ResultData addGoods(@Validated({AddGroup.class}) @RequestBody GoodsReqVO reqVO) {
        goodsService.addGoods(reqVO);
        return ResultUtil.success();
    }

    @DeleteMapping("/deleteGoods")
    @ApiOperation(value = "删除货物")
    public ResultData deleteGoods(@Validated @RequestBody IdsReqVO reqVO) {
        goodsService.deleteGoods(reqVO);
        return ResultUtil.success();
    }

    @GetMapping("/getGoods")
    @ApiOperation(value = "查询货物详情")
    public ResultData<GoodsRespVO> getGoods(@Validated IdReqVO reqVO) {
        return ResultUtil.success(goodsService.getGoods(reqVO));
    }

    @PutMapping("/updateGoods")
    @ApiOperation(value = "修改货物")
    public ResultData updateGoods(@Validated({UpdateGroup.class}) @RequestBody GoodsReqVO reqVO) {
        goodsService.updateGoods(reqVO);
        return ResultUtil.success();
    }

    @GetMapping("/goodsPage")
    @ApiOperation(value = "货物分页")
    public ResultData<PageResultVO<GoodsRespVO>> goodsPage(@Validated SupplierPageReqVO reqVO) {
        return ResultUtil.success(goodsService.goodsPage(reqVO));
    }

}
